/*
 * Created by SharpDevelop.
 * User: MyWife
 * Date: 1/1/2003
 * Time: 3:54 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Collections;
using popLib;
using System.IO;

namespace ClockGadget
{
	/// <summary>
	/// Description of ClockPanel.
	/// </summary>
	public partial class ClockPanel : SidebarControl//, UserControl
	{
		Image background;
		Hashtable options;
		public ClockPanel(SidebarGadget sidebarGadget):base(sidebarGadget)
		{			
			InitializeComponent();
			MouseLeaveFunc( panel2, new EventArgs() );
		}
		
		public override void StartComponent(){
			this.options = sidebarGadget.Options;
			string clockImage = Path.Combine( Start.dir_clock, options[Start.optionsType.Name+""]+".png" );
			
			if( File.Exists( clockImage ) )
				this.BackgroundImage = Image.FromFile( clockImage );
			else this.BackgroundImage = (Image)ClockRes.Simple;
			
			background 			= new Bitmap(130, 130);
			Graphics painter 	= Graphics.FromImage( background );
			Brush tBrush 		= new TextureBrush( (Image)this.BackgroundImage, new Rectangle(0, 0, 120, 120));
			painter.FillEllipse(tBrush, new Rectangle(10, 10, 110, 110) );
			tBrush.Dispose();
			painter.Dispose();
			
			timer1.Start();
		}
		
		
		
		void Timer1Tick(object sender, EventArgs e)
		{
			panel1.BackgroundImage = Start.drawClock( background, new Point(0,0), 
			                                         Color.FromName( options[Start.optionsType.Hour+""]+"" ), 
			                                         Color.FromName( options[Start.optionsType.Minute+""]+"" ),
			                                         Color.FromName( options[Start.optionsType.Second+""]+"" )
			                                        );
		}
		
		void MouseEnterFunc(object sender, EventArgs e)
		{
			Panel tmp = (Panel)sender;
			tmp.BackgroundImage = (Image)tmp.Tag;
		}
		
		void MouseLeaveFunc(object sender, EventArgs e)
		{
			Panel tmp = (Panel)sender;
			if(tmp.Tag==null) tmp.Tag = tmp.BackgroundImage;			
			tmp.BackgroundImage = ImageLib.changeImageOpacity( (Image)tmp.Tag, 0.2F );
		}
		
		void ActionEvent(object sender, EventArgs e)
		{
			sidebarGadget.ViewOptions();
		}
	}
}
